package com.zito.health.api.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zito.health.api.annotation.AppGetMapping;
import com.zito.health.api.annotation.AppPostMapping;
import com.zito.health.api.result.ResponseBean;
import com.zito.health.common.result.PageResult;
import com.zito.health.common.result.VerifyResult;
import com.zito.health.dto.LaboratoryCheckDto;
import com.zito.health.dto.LaboratoryDto;
import com.zito.health.entity.Laboratory;
import com.zito.health.entity.LaboratoryExamine;
import com.zito.health.service.LaboratoryAppService;
import com.zito.health.service.LaboratoryExamineService;
import com.zito.health.service.LaboratoryService;
import com.zito.health.service.UserService;
import com.zito.health.util.CacheUtil;
import com.zito.health.vo.LaboratoryAppVo;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.slf4j.XSlf4j;
import org.apache.poi.ddf.EscherColorRef;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/lab")
@Slf4j
public class LaboratoryAppController {

    @Autowired
    LaboratoryAppService laboratoryAppService;
    @Autowired
    LaboratoryService laboratoryService;
    @Autowired
    LaboratoryExamineService laboratoryExamineService;
    /**
     * 查询列表
     * @param pageNo
     * @param pageSize
     * @auth sun
     * @return
     */
    @AppGetMapping("/List")
    public ResponseBean List (@RequestParam(defaultValue = "0") Integer pageNo, @RequestParam(defaultValue = "10")Integer pageSize,Laboratory laboratory){
        PageHelper.startPage(pageNo,pageSize);
        List laboratoryList = laboratoryAppService.queryList(laboratory);
        PageInfo<LaboratoryAppVo> pageInfo = new PageInfo(laboratoryList);
        PageResult<LaboratoryAppVo> result = new PageResult();
        result.setRows(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return new ResponseBean(200,"",result);
    }

    /**
     * 查询详情
     * @param id
     * @return
     * @auth sun
     */
    @AppGetMapping("/{id}")
    public ResponseBean queryByid (@PathVariable Integer id){
        LaboratoryAppVo laboratoryAppVo = laboratoryAppService.queryByid(id);
        return new ResponseBean(200,"",laboratoryAppVo);
    }

    /**
     * 查询区/县未审核通过原因
     * @param id
     * @return
     * @auth sun
     */
    @AppGetMapping("/queryReturnReason")
    public ResponseBean queryReturnReason (Integer id){
        LaboratoryExamine laboratoryExamine = laboratoryExamineService.queryById(id);
        return new ResponseBean(200,"",laboratoryExamine);
    }

    /**
     * 实验室提交
     * @return
     * @auth sun
     */
    @AppPostMapping("/updateState")
    public ResponseBean updateState (Integer id){
        VerifyResult verifyResult = new VerifyResult();
        Laboratory laboratory = laboratoryService.queryById(id);
        laboratory.setStates(1); // 修改状态为 1 = 未审核
        laboratoryService.update(laboratory);
        return new ResponseBean(200,"",verifyResult);
    }

    /**
     * 区/县审核
     * @auth sun
     */
    @AppPostMapping("/countyAudit")
    public ResponseBean countyAudit(LaboratoryDto laboratoryDto){
        VerifyResult verifyResult = new VerifyResult();
        laboratoryAppService.countyAudit(laboratoryDto);
        return new ResponseBean(200,"",verifyResult);
    }

    /**
     * 市审核
     * @auth sun
     */
    @AppPostMapping("/cityAudit")
    public ResponseBean cityAudit(LaboratoryDto laboratoryDto){
        VerifyResult verifyResult = new VerifyResult();
        laboratoryAppService.cityAudit(laboratoryDto);
        return new ResponseBean(200,"",verifyResult);
    }
}
